package day18.edu;

import org.junit.Test;

import java.util.Arrays;

// Created: 18/09/2025, ChangJiang Ru
public class Product implements Comparable {
    private String name;
    private double price;

    public Product(String newName, double newPrice) {
        this.name = newName;
        this.price = newPrice;
    }

    public Product() {

    }

    public void setName(String newName) {
        this.name = newName;
    }

    public void setPrice(double newPrice) {
        this.price = newPrice;
    }

    public String getName() {
        return this.name;
    }

    public double getPrice() {
        return this.price;
    }

    @Override
    public int compareTo(Object o) {
        if (o == this) {
            return 0;
        }

        if (o instanceof Product) {
            Product p = (Product) o;
            int value = Double.compare(this.price, p.price); // From lower to upper
            if(value != 0)
            {
                return value;
            }

            return this.name.compareTo(p.name);
        }



        throw new RuntimeException("Type is error match");
    }

    @Override
    public String toString() {
        return "Product{" +
                "name ='" + name + '\'' +
                ", price ='" + price + '\'' +
                '}';
    }


}